//
// Created by yanhai on 2021/11/5.
//

// 共享队列

#pragma once

#include "hash_table_thread.h"

class SpareQueue {
public:
    typedef HashTableThreadBucketNode value_type;
    typedef unsigned int length_type;

    // 将node放入队列
    void Enqueue(value_type *node);

    // 从队列中取出node，有可能为空
    value_type *Dequeue();

    length_type Len() const;

private:
    value_type *top{nullptr};
    value_type *bot{nullptr};
    length_type len{0};
    mutable std::mutex mutex;
};

inline SpareQueue::length_type SpareQueue::Len() const
{
    std::lock_guard<std::mutex> lock(mutex);
    return len;
}

